{% extends "base.html" %}

{% block title %}Vehicles{% endblock %}

{% block subtitle %}Vehicle list{% endblock %}

{% block content %}
    {% if journal is defined and journal|length > 0 %}
        <div style="align-items: center;">
            {% for vehicle in journal %}
                {% set edit_link = "/edit_vehicle/" ~ vehicle['inventory_number'] %}
                {% if vehicle['type'] == "truck" %}
                    <div style="display: flex; flex-direction: column;">
                        <div>Type: Truck</div>
                        <div>Inventory number: {{ vehicle['inventory_number'] }}</div>
                        <div>Model: {{ vehicle['model'] }}</div>
                        <div>Year: {{ vehicle['year'] }}</div>
                        <div>Capacity: {{ vehicle['capacity'] }}</div>
                        <button style="margin: 10px;" onclick="location.href='{{ edit_link }}'">Edit vehicle</button>
                    </div>
                {% endif %}
                {% if vehicle['type'] == "car" %}
                    <div style="display: flex; flex-direction: column;">
                        <div>Type: Car</div>
                        <div>Inventory number: {{ vehicle['inventory_number'] }}</div>
                        <div>Model: {{ vehicle['model'] }}</div>
                        <div>Year: {{ vehicle['year'] }}</div>
                        <button style="margin: 10px;" onclick="location.href='{{ edit_link }}'">Edit vehicle</button>
                    </div>
                {% endif %}
            {% endfor %}
        </div>
    {% else %}
        <div style="padding: 10px; border: 3px dotted black;">List empty</div>
    {% endif %}
    <button style="margin: 10px;" onclick="location.href='/'">Return on main page</button>
{% endblock %}